package org.qqcui.designpattern.patterns.prototype.deepclone;

/**
 * 深拷贝的客户端类
 *
 * @author cuiqingqiang
 * @version 1.0
 * @date 2020-10-18 11:58
 **/
public class Client {
	public static void main(String[] args) throws CloneNotSupportedException {
		DeepClone deepClone = new DeepClone();
		deepClone.name = "宋江";
		deepClone.deepCloneTarget = new DeepCloneTarget("李逵", 22);

		// 方式一，通过clone的方式来实现深拷贝
		DeepClone copy = (DeepClone) deepClone.clone();
		System.out.println("deepClone" + deepClone.name + ",deepClone.deepCloneTarget=" + deepClone.deepCloneTarget.hashCode());
		System.out.println("copy" + copy.name + ",copy.deepCloneTarget=" + copy.deepCloneTarget.hashCode());
		System.out.println("deepClone" + deepClone.name + ",deepClone.finalTarget=" + deepClone.finalTarget.hashCode());
		System.out.println("copy" + copy.name + ",copy.finalTarget=" + copy.finalTarget.hashCode());

		// 方式二，通过序列化与反序列化的方式来实现深拷贝
		// DeepClone copy = deepClone.deepClone();
		// System.out.println("deepClone" + deepClone.name + ",deepClone.deepCloneTarget=" + deepClone.deepCloneTarget.hashCode());
		// System.out.println("copy" + copy.name + ",copy.deepCloneTarget=" + copy.deepCloneTarget.hashCode());
	}
}
